From 875063589de10482711914f9f6496101b661d235 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Niklas=20Laxstr=C3=B6m?= Date: Mon, 13 Jul 2009 10:34:31 +0000 Subject: [PATCH] Some escaping fixes and related readability changes --- includes/SkinTemplate.php | 1 + includes/specials/SpecialAllpages.php | 4 +- includes/specials/SpecialBlockip.php | 16 +- .../specials/SpecialDeletedContributions.php | 5 +- .../specials/SpecialFileDuplicateSearch.php | 12 +- .../specials/SpecialListUserRestrictions.php | 164 ++++++++++++++++++ includes/specials/SpecialMIMEsearch.php | 6 +- includes/specials/SpecialNewimages.php | 7 +- includes/specials/SpecialUpload.php | 2 +- languages/messages/MessagesEn.php | 2 +- 10 files changed, 192 insertions(+), 27 deletions(-) create mode 100644 includes/specials/SpecialListUserRestrictions.php diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 3c4858236b..edfdf0f3a1 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -324,6 +324,7 @@ class SkinTemplate extends Skin { $out->setSquidMaxage( 0 ); } } else if( count( $newtalks ) ) { + // _>" " for BC <= 1.16 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) ); $msgs = array(); foreach( $newtalks as $newtalk ) { diff --git a/includes/specials/SpecialAllpages.php b/includes/specials/SpecialAllpages.php index 1868935ffd..89f5d343e5 100644 --- a/includes/specials/SpecialAllpages.php +++ b/includes/specials/SpecialAllpages.php @@ -391,7 +391,7 @@ class SpecialAllpages extends IncludableSpecialPage { $prevLink = $sk->linkKnown( $self, - wfMsgHTML( 'prevpage', htmlspecialchars( $pt ) ), + htmlspecialchars( wfMsg( 'prevpage', $pt ) ), array(), $query ); @@ -408,7 +408,7 @@ class SpecialAllpages extends IncludableSpecialPage { $nextLink = $sk->linkKnown( $self, - wfMsgHtml( 'nextpage', htmlspecialchars( $t->getText() ) ), + htmlspecialchars( wfMsg( 'nextpage', $t->getText() ) ), array(), $query ); diff --git a/includes/specials/SpecialBlockip.php b/includes/specials/SpecialBlockip.php index a816aabe26..559c6886d8 100644 --- a/includes/specials/SpecialBlockip.php +++ b/includes/specials/SpecialBlockip.php @@ -671,15 +671,15 @@ class IPBlockForm { $query = array( 'action' => 'unblock' ); if( $this->BlockAddress ) { - $addr = htmlspecialchars( strtr( $this->BlockAddress, '_', ' ' ) ); - $message = wfMsgHtml( 'ipb-unblock-addr', $addr ); + $addr = strtr( $this->BlockAddress, '_', ' ' ); + $message = wfMsg( 'ipb-unblock-addr', $addr ); $query['ip'] = $this->BlockAddress; } else { - $message = wfMsgHtml( 'ipb-unblock' ); + $message = wfMsg( 'ipb-unblock' ); } return $skin->linkKnown( $list, - $message, + htmlspecialchars($message), array(), $query ); @@ -696,16 +696,16 @@ class IPBlockForm { $query = array(); if( $this->BlockAddress ) { - $addr = htmlspecialchars( strtr( $this->BlockAddress, '_', ' ' ) ); - $message = wfMsgHtml( 'ipb-blocklist-addr', $addr ); + $addr = strtr( $this->BlockAddress, '_', ' ' ); + $message = wfMsg( 'ipb-blocklist-addr', $addr ); $query['ip'] = $this->BlockAddress; } else { - $message = wfMsgHtml( 'ipb-blocklist' ); + $message = wfMsg( 'ipb-blocklist' ); } return $skin->linkKnown( $list, - $message, + htmlspecialchars($message), array(), $query ); diff --git a/includes/specials/SpecialDeletedContributions.php b/includes/specials/SpecialDeletedContributions.php index e0b11617c5..c57b2d5bb5 100644 --- a/includes/specials/SpecialDeletedContributions.php +++ b/includes/specials/SpecialDeletedContributions.php @@ -71,9 +71,10 @@ class DeletedContribsPager extends IndexPager { if ( isset( $this->mNavigationBar ) ) { return $this->mNavigationBar; } + $fmtLimit = $wgLang->formatNum( $this->mLimit ); $linkTexts = array( - 'prev' => wfMsgHtml( 'pager-newer-n', $this->mLimit ), - 'next' => wfMsgHtml( 'pager-older-n', $this->mLimit ), + 'prev' => wfMsgExt( 'pager-newer-n', array( 'escape', 'parsemag' ), $fmtLimit ), + 'next' => wfMsgExt( 'pager-older-n', array( 'escape', 'parsemag' ), $fmtLimit ), 'first' => wfMsgHtml( 'histlast' ), 'last' => wfMsgHtml( 'histfirst' ) ); diff --git a/includes/specials/SpecialFileDuplicateSearch.php b/includes/specials/SpecialFileDuplicateSearch.php index 716669337c..b86fcbea6f 100644 --- a/includes/specials/SpecialFileDuplicateSearch.php +++ b/includes/specials/SpecialFileDuplicateSearch.php @@ -125,14 +125,14 @@ function wfSpecialFileDuplicateSearch( $par = null ) { # Show a short summary if( $count == 1 ) { - $wgOut->addHTML( '

' . - wfMsgHtml( 'fileduplicatesearch-result-1', $filename ) . - '

' + $wgOut->wrapWikiMsg( + "

\n$1\n

", + array( 'fileduplicatesearch-result-1', $filename ) ); } elseif ( $count > 1 ) { - $wgOut->addHTML( '

' . - wfMsgExt( 'fileduplicatesearch-result-n', array( 'parseinline' ), $filename, $wgLang->formatNum( $count - 1 ) ) . - '

' + $wgOut->wrapWikiMsg( + "

\n$1\n

", + array( 'fileduplicatesearch-result-n', $filename, $wgLang->formatNum( $count - 1 ) ) ); } } diff --git a/includes/specials/SpecialListUserRestrictions.php b/includes/specials/SpecialListUserRestrictions.php new file mode 100644 index 0000000000..e900e98cfd --- /dev/null +++ b/includes/specials/SpecialListUserRestrictions.php @@ -0,0 +1,164 @@ +addWikiMsg( 'listuserrestrictions-intro' ); + $f = new SpecialListUserRestrictionsForm(); + $wgOut->addHTML( $f->getHTML() ); + + if( !mt_rand( 0, 10 ) ) + UserRestriction::purgeExpired(); + $pager = new UserRestrictionsPager( $f->getConds() ); + if( $pager->getNumRows() ) + $wgOut->addHTML( $pager->getNavigationBar() . + Xml::tags( 'ul', null, $pager->getBody() ) . + $pager->getNavigationBar() + ); + elseif( $f->getConds() ) + $wgOut->addWikiMsg( 'listuserrestrictions-notfound' ); + else + $wgOut->addWikiMsg( 'listuserrestrictions-empty' ); +} + +class SpecialListUserRestrictionsForm { + public function getHTML() { + global $wgRequest, $wgScript; + $action = htmlspecialchars( $wgScript ); + $s = ''; + $s .= Xml::fieldset( wfMsg( 'listuserrestrictions-legend' ) ); + $s .= "
"; + $s .= Xml::hidden( 'title', SpecialPage::getTitleFor('ListUserRestrictions')->getPrefixedDbKey() ); + $s .= Xml::label( wfMsg( 'listuserrestrictions-type' ), 'type' ) . ' ' . + self::typeSelector( 'type', $wgRequest->getVal( 'type' ), 'type' ); + $s .= ' '; + $s .= Xml::inputLabel( wfMsg( 'listuserrestrictions-user' ), 'user', 'user', + false, $wgRequest->getVal( 'user' ) ); + $s .= '

'; + $s .= Xml::label( wfMsg( 'listuserrestrictions-namespace' ), 'namespace' ) . ' ' . + Xml::namespaceSelector( $wgRequest->getVal( 'namespace' ), '', 'namespace' ); + $s .= ' '; + $s .= Xml::inputLabel( wfMsg( 'listuserrestrictions-page' ), 'page', 'page', + false, $wgRequest->getVal( 'page' ) ); + $s .= Xml::submitButton( wfMsg( 'listuserrestrictions-submit' ) ); + $s .= "

"; + return $s; + } + + public static function typeSelector( $name = 'type', $value = '', $id = false ) { + $s = new XmlSelect( $name, $id, $value ); + $s->addOption( wfMsg( 'userrestrictiontype-none' ), '' ); + $s->addOption( wfMsg( 'userrestrictiontype-page' ), UserRestriction::PAGE ); + $s->addOption( wfMsg( 'userrestrictiontype-namespace' ), UserRestriction::NAMESPACE ); + return $s->getHTML(); + } + + public function getConds() { + global $wgRequest; + $conds = array(); + + $type = $wgRequest->getVal( 'type' ); + if( in_array( $type, array( UserRestriction::PAGE, UserRestriction::NAMESPACE ) ) ) + $conds['ur_type'] = $type; + + $user = $wgRequest->getVal( 'user' ); + if( $user ) + $conds['ur_user_text'] = $user; + + $namespace = $wgRequest->getVal( 'namespace' ); + if( $namespace || $namespace === '0' ) + $conds['ur_namespace'] = $namespace; + + $page = $wgRequest->getVal( 'page' ); + $title = Title::newFromText( $page ); + if( $title ) { + $conds['ur_page_namespace'] = $title->getNamespace(); + $conds['ur_page_title'] = $title->getDBkey(); + } + + return $conds; + } +} + +class UserRestrictionsPager extends ReverseChronologicalPager { + public $mConds; + + public function __construct( $conds = array() ) { + $this->mConds = $conds; + parent::__construct(); + } + + public function getStartBody() { + # Copied from Special:Ipblocklist + wfProfileIn( __METHOD__ ); + # Do a link batch query + $this->mResult->seek( 0 ); + $lb = new LinkBatch; + + # Faster way + # Usernames and titles are in fact related by a simple substitution of space -> underscore + # The last few lines of Title::secureAndSplit() tell the story. + foreach( $this->mResult as $row ) { + $name = str_replace( ' ', '_', $row->ur_by_text ); + $lb->add( NS_USER, $name ); + $lb->add( NS_USER_TALK, $name ); + $name = str_replace( ' ', '_', $row->ur_user_text ); + $lb->add( NS_USER, $name ); + $lb->add( NS_USER_TALK, $name ); + if( $row->ur_type == UserRestriction::PAGE ) + $lb->add( $row->ur_page_namespace, $row->ur_page_title ); + } + $lb->execute(); + wfProfileOut( __METHOD__ ); + return ''; + } + + public function getQueryInfo() { + return array( + 'tables' => 'user_restrictions', + 'fields' => '*', + 'conds' => $this->mConds, + ); + } + + public function formatRow( $row ) { + return self::formatRestriction( UserRestriction::newFromRow( $row ) ); + } + + // Split off for use on Special:RestrictUser + public static function formatRestriction( $r ) { + global $wgUser, $wgLang; + $sk = $wgUser->getSkin(); + $timestamp = $wgLang->timeanddate( $r->getTimestamp(), true ); + $blockerlink = $sk->userLink( $r->getBlockerId(), $r->getBlockerText() ) . + $sk->userToolLinks( $r->getBlockerId(), $r->getBlockerText() ); + $subjlink = $sk->userLink( $r->getSubjectId(), $r->getSubjectText() ) . + $sk->userToolLinks( $r->getSubjectId(), $r->getSubjectText() ); + $expiry = is_numeric( $r->getExpiry() ) ? + wfMsg( 'listuserrestrictions-row-expiry', $wgLang->timeanddate( $r->getExpiry() ) ) : + wfMsg( 'ipbinfinite' ); + $msg = ''; + if( $r->isNamespace() ) { + $msg = wfMsgHtml( 'listuserrestrictions-row-ns', $subjlink, + htmlspecialchars( $wgLang->getDisplayNsText( $r->getNamespace() ) ), + htmlspecialchars( $expiry ) + ); + } + if( $r->isPage() ) { + $pagelink = $sk->link( $r->getPage() ); + $msg = wfMsgHtml( 'listuserrestrictions-row-page', $subjlink, + $pagelink, htmlspecialchars( $expiry ) ); + } + $reason = $sk->commentBlock( $r->getReason() ); + $removelink = ''; + if( $wgUser->isAllowed( 'restrict' ) ) { + $removelink = '(' . $sk->link( SpecialPage::getTitleFor( 'RemoveRestrictions' ), + wfMsgHtml( 'listuserrestrictions-remove' ), array(), array( 'id' => $r->getId() ) ) . ')'; + } + return "
  • {$timestamp}, {$blockerlink} {$msg} {$reason} {$removelink}
  • \n"; + } + + public function getIndexField() { + return 'ur_timestamp'; + } +} diff --git a/includes/specials/SpecialMIMEsearch.php b/includes/specials/SpecialMIMEsearch.php index 194836ed35..dafe003e73 100644 --- a/includes/specials/SpecialMIMEsearch.php +++ b/includes/specials/SpecialMIMEsearch.php @@ -73,8 +73,10 @@ class MIMEsearchPage extends QueryPage { $download = $skin->makeMediaLinkObj( $nt, wfMsgHtml( 'download' ) ); $bytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape'), $wgLang->formatNum( $result->img_size ) ); - $dimensions = wfMsgHtml( 'widthheight', $wgLang->formatNum( $result->img_width ), - $wgLang->formatNum( $result->img_height ) ); + $dimensions = htmlspecialchars( wfMsg( 'widthheight', + $wgLang->formatNum( $result->img_width ), + $wgLang->formatNum( $result->img_height ) + ) ); $user = $skin->link( Title::makeTitle( NS_USER, $result->img_user_text ), htmlspecialchars( $result->img_user_text ) ); $time = htmlspecialchars( $wgLang->timeanddate( $result->img_timestamp ) ); diff --git a/includes/specials/SpecialNewimages.php b/includes/specials/SpecialNewimages.php index a874773a52..96fea669db 100644 --- a/includes/specials/SpecialNewimages.php +++ b/includes/specials/SpecialNewimages.php @@ -188,14 +188,11 @@ function wfSpecialNewimages( $par, $specialPage ) { $searchpar ); - $message = wfMsgHtml( - 'showhidebots', - ( $hidebots ? wfMsgHtml( 'show' ) : wfMsgHtml( 'hide' ) ) - ); + $showhide = $hidebots ? wfMsg( 'show' ) : wfMsg( 'hide' ); $botLink = $sk->linkKnown( $titleObj, - $message, + htmlspecialchars( wfMsg( 'showhidebots', $showhide ) ), array(), $query ); diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index b78993b0bb..9b288165d6 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -545,7 +545,7 @@ class UploadForm { $skin = $wgUser->getSkin(); $wsize = $skin->formatSize( $wgUploadSizeWarning ); $asize = $skin->formatSize( $this->mFileSize ); - $warning .= '
  • ' . wfMsgHtml( 'large-file', $wsize, $asize ) . '
  • '; + $warning .= '
  • ' . htmlspecialchars( wfMsg( 'large-file', $wsize, $asize ) ) . '
  • '; } if ( $this->mFileSize == 0 ) { $warning .= '
  • '.wfMsgHtml( 'emptyfile' ).'
  • '; diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 084c29ca58..b2c6350770 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -889,7 +889,7 @@ See [[Special:Version|version page]].', 'newmessageslink' => 'new messages', 'newmessagesdifflink' => 'last change', 'youhavenewmessagesmulti' => 'You have new messages on $1', -'newtalkseparator' => ',_', # do not translate or duplicate this message to other languages +'newtalkseparator' => ', ', # do not translate or duplicate this message to other languages 'editsection' => 'edit', 'editsection-brackets' => '[$1]', # only translate this message to other languages if you have to change it 'editold' => 'edit', -- 2.20.1